<template>
<form class="info_Form" @submit="submitFun" v-if="fxDetail">
    <view class="inputGroup">
      <input name="trueName" :value="UserInfo.trueName" placeholder="真实姓名（如-张三）"></input>
      <block v-if="fxDetail.fxSetting.yinhangTixian==1">
          <input name="bankName" :value="UserInfo.bankName" placeholder="开户行(如-中国农业银行)"></input>
          <input name="subBankName" :value="UserInfo.subBankName" placeholder="支行名称"></input>
          <input name="bankNo" :value="UserInfo.bankNo" placeholder=" 银行账户"></input>
      </block>
      <input name="zfbNo" :value="UserInfo.zfbNo" placeholder="支付宝账户" v-if="fxDetail.fxSetting.zhifubaoTixian==1"></input>
    </view>
    <!-- <checkbox-group class='CheckBox' bindchange="checkboxChange">
      <label>
        <text>同意《用户三级分销协议》</text>
        <checkbox checked='{{agree}}' value='agree' color='{{setting.platformSetting.defaultColor}}'></checkbox>
      </label>  
    </checkbox-group> -->
    <button formType="submit" :disabled="!agree" class="signIn" :style="'background:' + setting.platformSetting.defaultColor">立即提交</button>
  </form>

  <!-- <button  class='footer_botton' bindtap='lookUserXY' style='color:{{setting.platformSetting.defaultColor}}'>
    查看《用户三级分销协议》
  </button> -->
</template>

<script>

export default {
  data() {
    return {
      agree: true,
      UserInfo: {},
      info: {
        trueName: '',
        bankName: '',
        subBankName: '',
        bankNo: '',
        zfbNo: ''
      },
      clientNo: '',
      setting: "",
      loginUser: "",
      fxDetail:'',
    };
  },

  components: {},
  props: {},

  /* lookUserXY: function () {
    wx.navigateTo({
      url: '/pages/regist_xieyi/index',
    })
  }, */

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getSessionUserInfo();
    this.get_fx_detailFun()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      setting: getApp().globalData.setting,
      clientNo: getApp().globalData.clientNo
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},
  methods: {
    //获取推广中心，查看是否有资格
    get_fx_detailFun: function () {
      console.log('-------推广中心--------');
      var customIndex = getApp().globalData.AddClientUrl("/wx_get_fx_data.html");
      var that = this; 
      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("===get_fx_detail===", res);
          if (res.data.errcode == '0') {
            let fxDetail = res.data.relateObj;
            that.setData({
              fxDetail: fxDetail
            });
          }

          wx.hideLoading();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    submitFun: function (e) {
      var info = e.detail.value;

      if (!info.trueName) {
        //|| !info.bankName || !info.subBankName || !info.bankNo || !info.zfbNo
        wx.showToast({
          title: '输入为空',
          image: '/wxcomponents/images/icons/tip.png',
          duration: 1000
        });
      } else {
        this.postParams(info);
      }
    },
    postParams: function (info) {
      var that = this; // wx.showLoading({
      //   title: 'loading'
      // })

      getApp().globalData.showToastLoading('loading', true);
      var postParamUserBank = getApp().globalData.AddClientUrl("/set_user_bank_info_setting.html", info, 'post');
      wx.request({
        url: postParamUserBank.url,
        data: postParamUserBank.params,
        method: 'POST',
        header: getApp().globalData.headerPost,
        success: function (res) {
          if (res.data.errcode == '0') {
            wx.showToast({
              title: '成功'
            });
            setTimeout(function () {
              wx.navigateBack();
            }, 2000);
          } else {
            wx.showToast({
              title: res.data.errMsg,
              image: '/wxcomponents/images/icons/tip.png',
              duration: 1000
            });
          }

          console.log(res.data);
        },
        fail: function (res) {
          console.log(res.data);
        },
        complete: function (res) {
          wx.hideLoading();
        }
      });
    },
    checkboxChange: function (e) {
      console.log(e.detail.value[0]);

      if (e.detail.value.length == 1) {
        this.setData({
          agree: true
        });
      } else {
        this.setData({
          agree: false
        });
      }
    },
    getSessionUserInfo: function () {
      var that = this; // wx.showLoading({
      //   title: 'loading'
      // })

      getApp().globalData.showToastLoading('loading', true);
      var postParamUserBank = getApp().globalData.AddClientUrl("/get_session_userinfo.html");
      wx.request({
        url: postParamUserBank.url,
        data: postParamUserBank.params,
        header: getApp().globalData.headerPost,
        success: function (res) {
          console.log(res.data);

          if (res.data.errcode == '0') {
            that.setData({
              UserInfo: res.data.relateObj.platformUser
            });
          } else {
            wx.showToast({
              title: res.data.errMsg,
              image: '/wxcomponents/images/icons/tip.png',
              duration: 1000
            });
          }
        },
        fail: function (res) {
          console.log(res.data);
        },
        complete: function (res) {
          wx.hideLoading();
        }
      });
    },
    loginIn: function (data) {
      console.log(data);
      var that = this; // wx.showLoading({
      //   title: 'loading',
      //   mask: true
      // })

      getApp().globalData.showToastLoading('loading', true);
      var loginUrl = getApp().globalData.AddClientUrl("Client.User.Login", data, 'post');
      wx.request({
        url: loginUrl.url,
        data: loginUrl.params,
        method: 'POST',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function (res) {
          console.log(res.header);
          var header = res.header;
          var cookie = null;

          if (!!header['Set-Cookie']) {
            cookie = header['Set-Cookie'];
          }

          if (!!header['set-cookie']) {
            cookie = header['set-cookie'];
          }

          console.log(cookie);
          wx.hideLoading(); //console.log(res.data)

          if (res.data.errcode == 0) {
            wx.setStorage({
              key: "cookie",
              data: cookie
            });
            getApp().globalData.header = {
              'content-type': 'application/json',
              // 默认值
              'Cookie': cookie
            }; // wx.setStorageSync('cookie', cookie)

            getApp().globalData.cookie = cookie;
            getApp().globalData.loginUser = res.data.relateObj;
            that.setData({
              loginUser: res.data.relateObj
            });
            wx.setStorage({
              key: "loginUser",
              data: res.data.relateObj
            });
            wx.showToast({
              title: '登录成功',
              icon: 'success',
              duration: 2000,
              success: function () {
                wx.getStorageInfo({
                  success: function (res) {
                    console.log("本地缓存.............");
                    console.log(res.keys);

                    for (let i = 0; i < res.keys.length; i++) {
                      wx.getStorage({
                        key: res.keys[i],
                        success: function (res) {
                          console.log(res.data);
                        }
                      });
                    }
                  }
                });
                getApp().globalData.toIndex();
              }
            });
          } else {
            //
            wx.showToast({
              title: '登录失败',
              icon: 'loading',
              duration: 1500
            });
          }
        },
        fail: function (res) {
          console.log("fail");
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style>
@import "./index.css";
</style>